package com.ruoyi.train.service.impl;

import java.net.MalformedURLException;
import java.util.*;
import java.util.List;

import com.ruoyi.train.domain.*;
import com.ruoyi.train.domain.Vo.ExamApplicationVo;
import com.ruoyi.train.domain.Vo.StudentInformationVo;
import com.ruoyi.train.mapper.ExamApplicationMapper;
import com.ruoyi.train.mapper.ExamApplicationStudentMapper;
import com.ruoyi.train.mapper.StudentInformationMapper;
import com.ruoyi.train.service.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itextpdf.io.image.ImageDataFactory;
import com.itextpdf.layout.element.Image;

import com.ruoyi.common.domain.TrainingInstitutionInfomation;
import com.ruoyi.common.service.ITrainingInstitutionInfomationService;

import com.ruoyi.config.pdf.method.PdfCreate;
import com.ruoyi.config.pdf.vo.PdfReqVo;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.system.service.ISysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 提交考试申请Service业务层处理
 *
 * @author wusihao
 * @date 2023-03-26
 */
@Service
public class ExamApplicationServiceImpl extends ServiceImpl<ExamApplicationMapper, ExamApplication> implements IExamApplicationService
{
    @Autowired
    private ExamApplicationMapper examApplicationMapper;
    @Autowired
    private ExamApplicationStudentMapper examApplicationStudentMapper;

    @Autowired
    private IStudentInformationService studentInformationService;

    @Autowired
    private IStudentProcessRecordService studentProcessRecordService;

    @Autowired
    private ITrainPlanService trainPlanService;
    @Autowired
    private ITrainClassService trainClassService;

    @Autowired
    private IExamPassCertificateService examPassCertificateService;

    @Autowired
    private StudentInformationMapper studentInformationMapper;

    @Autowired
    private IExamPassStudentService examPassStudentService;

    @Autowired
    private ITrainingInstitutionInfomationService trainingInstitutionInfomationService;

    @Autowired
    private IExamApplicationStudentService examApplicationStudentService;
    @Autowired
    private IExamApplicationService examApplicationService;

    @Autowired
    private ISysDictDataService dictDataService;

    /**
     * 查询提交考试申请
     *
     * @param id 提交考试申请主键
     * @return 提交考试申请
     */
    @Override
    public ExamApplication selectExamApplicationById(Long id)
    {
        ExamApplication examApplication = examApplicationMapper.selectExamApplicationById(id);

        return examApplication;
    }

    /**
     * 查询提交考试申请列表
     *
     * @param examApplication 提交考试申请
     * @return 提交考试申请
     */
    @Override
    public List<ExamApplication> selectExamApplicationList(ExamApplication examApplication)
    {
        return examApplicationMapper.selectExamApplicationList(examApplication);
    }

    /**
     * 新增提交考试申请
     *
     * @param examApplication 提交考试申请
     * @return 结果
     */
    @Override
    public int insertExamApplication(ExamApplication examApplication)
    {
        examApplication.setCreateTime(DateUtils.getNowDate());
        return examApplicationMapper.insertExamApplication(examApplication);
    }



    // 通过考试申请表id得到考试申请学生信息
    private List<StudentInformationVo> getExamApplicationStudentInfoByExamApplicationId(Long id) {
        // 通过考试申请学生表得到学生id
        QueryWrapper<ExamApplicationStudent> examApplicationStudentQueryWrapper = new QueryWrapper<>();
        examApplicationStudentQueryWrapper.eq("exam_application_id", id);
        List<ExamApplicationStudent> examApplicationStudents = examApplicationStudentService.list(examApplicationStudentQueryWrapper);
        // 定义返回结果集合
        List<StudentInformationVo> studentInformationVoList = new ArrayList<>();
        for (ExamApplicationStudent examApplicationStudent : examApplicationStudents) {
            // 定义存储集合
            StudentInformationVo studentInformationVo = new StudentInformationVo();
            // 得到学生id
            // 通过学生id查询学生基本信息表
            Long studentId = examApplicationStudent.getStudentId();
            QueryWrapper<StudentInformation> studentInformationQueryWrapper = new QueryWrapper<>();
            studentInformationQueryWrapper.eq("id", studentId);
            studentInformationQueryWrapper.eq("is_deleted", 0);
            StudentInformation studentInformationServiceOne = studentInformationService.getOne(studentInformationQueryWrapper);
            if (studentInformationServiceOne == null ) continue;;

            // 通过学生编号得到学生记录表
            QueryWrapper<StudentProcessRecord> studentProcessRecordQueryWrapper = new QueryWrapper<>();
            studentProcessRecordQueryWrapper.eq("serial_number", studentInformationServiceOne.getSerialNumber());
            studentProcessRecordQueryWrapper.eq("exam_application_is_pass", 1);
            StudentProcessRecord studentProcessRecordServiceOne = studentProcessRecordService.getOne(studentProcessRecordQueryWrapper);
            if (studentProcessRecordServiceOne == null) continue;
            // 存入答案集合
            BeanUtils.copyProperties(studentProcessRecordServiceOne, studentInformationVo);
            BeanUtils.copyProperties(studentInformationServiceOne, studentInformationVo);

            studentInformationVoList.add(studentInformationVo);
        }

        return studentInformationVoList;
    }

    /**
     * 批量删除提交考试申请
     *
     * @param ids 需要删除的提交考试申请主键
     * @return 结果
     */
    @Override
    public int deleteExamApplicationByIds(Long[] ids)
    {
        return examApplicationMapper.deleteExamApplicationByIds(ids);
    }

    /**
     * 删除提交考试申请信息
     *
     * @param id 提交考试申请主键
     * @return 结果
     */
    @Override
    public int deleteExamApplicationById(Long id)
    {
        return examApplicationMapper.deleteExamApplicationById(id);
    }

    @Override
    public List<ExamApplicationVo> selectExamApplicationVoList(ExamApplicationVo examApplicationVo) {


        QueryWrapper<ExamApplication> examApplicationQueryWrapper = new QueryWrapper<>();
        examApplicationQueryWrapper.eq(examApplicationVo.getExamPlace() != null, "exam_place", examApplicationVo.getExamPlace());
        examApplicationQueryWrapper.eq("is_deleted", 0);
        examApplicationQueryWrapper.eq("is_pass", 0);
        examApplicationQueryWrapper.eq("create_id", SecurityUtils.getUserId());
        List<ExamApplication> examApplications = examApplicationMapper.selectList(examApplicationQueryWrapper);
        // 存储答案返回对象
        List<ExamApplicationVo> examApplicationVos = new ArrayList<>();
        List<StudentInformationVo> studentInformationVoList = new ArrayList<>();
        // 将所有信息填入Vo中
        for (ExamApplication examApplication : examApplications) {
            ExamApplicationVo examApplicationVotemp = new ExamApplicationVo();
            // 将考试申请表的内容复制到其Vo类中
            BeanUtils.copyProperties(examApplication, examApplicationVotemp);

            // 得到考试申请表id
            Long examApplicationId = examApplication.getId();
            // 通过考试申请表id找到考试申请表中的学生
            QueryWrapper<ExamApplicationStudent> examApplicationStudentQueryWrapper = new QueryWrapper<>();
            examApplicationStudentQueryWrapper.eq("exam_application_id", examApplicationId);
            List<ExamApplicationStudent> examApplicationStudents = examApplicationStudentMapper.selectList(examApplicationStudentQueryWrapper);
            // 培训计划id
            Long trainPlanId = 0L;
            Long classId = 0L;
            // 循环考试申请表中的学生信息
            for (ExamApplicationStudent examApplicationStudent : examApplicationStudents) {
                // 通过学生id找到学生信息表
                Long studentId = examApplicationStudent.getStudentId();
                QueryWrapper<StudentInformation> studentInformationQueryWrapper = new QueryWrapper<>();
                studentInformationQueryWrapper.eq("id", studentId);
                List<StudentInformation> studentInformationList = studentInformationService.list(studentInformationQueryWrapper);

                // 遍历学生信息表
                for (StudentInformation studentInformation : studentInformationList) {
                    classId = studentInformation.getClassId();
                    // 通过学生编号查询学生记录表
                    String serialNumber = studentInformation.getSerialNumber();
                    QueryWrapper<StudentProcessRecord> studentProcessRecordQueryWrapper = new QueryWrapper<>();
                    studentProcessRecordQueryWrapper.eq("serial_number", serialNumber);
                    StudentProcessRecord studentProcessRecord = studentProcessRecordService.getOne(studentProcessRecordQueryWrapper);
                    // 得到培训计划id
                    trainPlanId = studentProcessRecord.getTrainPlanId();
                    // 将信息导入StudentInfoVo类中
                    StudentInformationVo studentInformationVo = new StudentInformationVo();
                    BeanUtils.copyProperties(studentInformation, studentInformationVo);
                    BeanUtils.copyProperties(studentProcessRecord, studentInformationVo);
                    // 将信息加入到返回集合中
                    studentInformationVoList.add(studentInformationVo);
                }
            }

            // 将学生集合加入考试申请表Vo中
            if (studentInformationVoList != null) examApplicationVotemp.setStudentInformationVoList(studentInformationVoList);
            // 通过培训计划id找到培训计划表，得到培训计划申请
            TrainPlan trainPlan = trainPlanService.selectTrainPlanById(trainPlanId);
            if (trainPlan != null && trainPlan.getTrainplanApplication() != null) examApplicationVotemp.setTrainplanApplication(trainPlan.getTrainplanApplication());
            // 根据班级id找到培训班级信息
            TrainClass trainClass = trainClassService.selectTrainClassById(classId);
            if (trainClass != null) BeanUtils.copyProperties(trainClass, examApplicationVotemp);

            examApplicationVotemp.setId(examApplicationId);

            examApplicationVos.add(examApplicationVotemp);
        }
        return examApplicationVos;
    }

    @Override
    public int submitExamApplication1(Long examApplicationId) {
        ExamApplication examApplication = examApplicationMapper.selectById(examApplicationId);
        examApplication.setApprovalProcessSign(1L);

        return examApplicationMapper.updateById(examApplication);
    }

    @Override
    public List<ExamApplicationVo> selectadminExamApplicationVoList(ExamApplicationVo examApplicationVo) {
        QueryWrapper<ExamApplication> examApplicationQueryWrapper = new QueryWrapper<>();
        examApplicationQueryWrapper.eq(examApplicationVo.getExamPlace() != null, "exam_place", examApplicationVo.getExamPlace());
        examApplicationQueryWrapper.eq("is_deleted", 0);
        examApplicationQueryWrapper.eq("approval_process_sign", 1L);
        List<ExamApplication> examApplications = examApplicationMapper.selectList(examApplicationQueryWrapper);
        // 存储答案返回对象
        List<ExamApplicationVo> examApplicationVos = new ArrayList<>();
        List<StudentInformationVo> studentInformationVoList = new ArrayList<>();
        // 将所有信息填入Vo中
        for (ExamApplication examApplication : examApplications) {
            ExamApplicationVo examApplicationVotemp = new ExamApplicationVo();
            // 将考试申请表的内容复制到其Vo类中
            BeanUtils.copyProperties(examApplication, examApplicationVotemp);

            // 得到考试申请表id
            Long examApplicationId = examApplication.getId();
            // 通过考试申请表id找到考试申请表中的学生
            QueryWrapper<ExamApplicationStudent> examApplicationStudentQueryWrapper = new QueryWrapper<>();
            examApplicationStudentQueryWrapper.eq("exam_application_id", examApplicationId);
            List<ExamApplicationStudent> examApplicationStudents = examApplicationStudentMapper.selectList(examApplicationStudentQueryWrapper);
            // 培训计划id
            Long trainPlanId = 0L;
            Long classId = 0L;
            // 循环考试申请表中的学生信息
            for (ExamApplicationStudent examApplicationStudent : examApplicationStudents) {
                // 通过学生id找到学生信息表
                Long studentId = examApplicationStudent.getStudentId();
                QueryWrapper<StudentInformation> studentInformationQueryWrapper = new QueryWrapper<>();
                studentInformationQueryWrapper.eq("id", studentId);
                List<StudentInformation> studentInformationList = studentInformationService.list(studentInformationQueryWrapper);

                // 遍历学生信息表
                for (StudentInformation studentInformation : studentInformationList) {
                    classId = studentInformation.getClassId();
                    // 通过学生编号查询学生记录表
                    String serialNumber = studentInformation.getSerialNumber();
                    QueryWrapper<StudentProcessRecord> studentProcessRecordQueryWrapper = new QueryWrapper<>();
                    studentProcessRecordQueryWrapper.eq("serial_number", serialNumber);
                    studentProcessRecordQueryWrapper.eq("exam_application_is_pass", 1);
                    StudentProcessRecord studentProcessRecord = studentProcessRecordService.getOne(studentProcessRecordQueryWrapper);
                    if (studentProcessRecord == null) continue;
                    // 得到培训计划id
                    trainPlanId = studentProcessRecord.getTrainPlanId();
                    // 将信息导入StudentInfoVo类中
                    StudentInformationVo studentInformationVo = new StudentInformationVo();
                    BeanUtils.copyProperties(studentInformation, studentInformationVo);
                    BeanUtils.copyProperties(studentProcessRecord, studentInformationVo);
                    // 将信息加入到返回集合中
                    studentInformationVoList.add(studentInformationVo);
                }
            }

            // 将学生集合加入考试申请表Vo中
            if (studentInformationVoList != null) examApplicationVotemp.setStudentInformationVoList(studentInformationVoList);
            // 通过培训计划id找到培训计划表，得到培训计划申请
            TrainPlan trainPlan = trainPlanService.selectTrainPlanById(trainPlanId);
            if (trainPlan != null && trainPlan.getTrainplanApplication() != null) examApplicationVotemp.setTrainplanApplication(trainPlan.getTrainplanApplication());
            // 根据班级id找到培训班级信息
            TrainClass trainClass = trainClassService.selectTrainClassById(classId);
            if (trainClass != null) BeanUtils.copyProperties(trainClass, examApplicationVotemp);

            examApplicationVotemp.setId(examApplicationId);

            examApplicationVos.add(examApplicationVotemp);
        }
        return examApplicationVos;
    }

    @Override
    public List<ExamApplicationVo> selectfuzerenExamApplicationVoList(ExamApplicationVo examApplicationVo) {
        QueryWrapper<ExamApplication> examApplicationQueryWrapper = new QueryWrapper<>();
        examApplicationQueryWrapper.eq(examApplicationVo.getExamPlace() != null, "exam_place", examApplicationVo.getExamPlace());
        examApplicationQueryWrapper.eq("is_deleted", 0);
        examApplicationQueryWrapper.eq("approval_process_sign", 2);
        List<ExamApplication> examApplications = examApplicationMapper.selectList(examApplicationQueryWrapper);
        // 存储答案返回对象
        List<ExamApplicationVo> examApplicationVos = new ArrayList<>();
        List<StudentInformationVo> studentInformationVoList = new ArrayList<>();
        // 将所有信息填入Vo中
        for (ExamApplication examApplication : examApplications) {
            ExamApplicationVo examApplicationVotemp = new ExamApplicationVo();
            // 将考试申请表的内容复制到其Vo类中
            BeanUtils.copyProperties(examApplication, examApplicationVotemp);

            // 得到考试申请表id
            Long examApplicationId = examApplication.getId();
            // 通过考试申请表id找到考试申请表中的学生
            QueryWrapper<ExamApplicationStudent> examApplicationStudentQueryWrapper = new QueryWrapper<>();
            examApplicationStudentQueryWrapper.eq("exam_application_id", examApplicationId);
            List<ExamApplicationStudent> examApplicationStudents = examApplicationStudentMapper.selectList(examApplicationStudentQueryWrapper);
            // 培训计划id
            Long trainPlanId = 0L;
            Long classId = 0L;
            // 循环考试申请表中的学生信息
            for (ExamApplicationStudent examApplicationStudent : examApplicationStudents) {
                // 通过学生id找到学生信息表
                Long studentId = examApplicationStudent.getStudentId();
                QueryWrapper<StudentInformation> studentInformationQueryWrapper = new QueryWrapper<>();
                studentInformationQueryWrapper.eq("id", studentId);
                List<StudentInformation> studentInformationList = studentInformationService.list(studentInformationQueryWrapper);

                // 遍历学生信息表
                for (StudentInformation studentInformation : studentInformationList) {
                    classId = studentInformation.getClassId();
                    // 通过学生编号查询学生记录表
                    String serialNumber = studentInformation.getSerialNumber();
                    QueryWrapper<StudentProcessRecord> studentProcessRecordQueryWrapper = new QueryWrapper<>();
                    studentProcessRecordQueryWrapper.eq("serial_number", serialNumber);
                    StudentProcessRecord studentProcessRecord = studentProcessRecordService.getOne(studentProcessRecordQueryWrapper);
                    // 得到培训计划id
                    trainPlanId = studentProcessRecord.getTrainPlanId();
                    // 将信息导入StudentInfoVo类中
                    StudentInformationVo studentInformationVo = new StudentInformationVo();
                    BeanUtils.copyProperties(studentInformation, studentInformationVo);
                    BeanUtils.copyProperties(studentProcessRecord, studentInformationVo);
                    // 将信息加入到返回集合中
                    studentInformationVoList.add(studentInformationVo);
                }
            }

            // 将学生集合加入考试申请表Vo中
            if (studentInformationVoList != null) examApplicationVotemp.setStudentInformationVoList(studentInformationVoList);
            // 通过培训计划id找到培训计划表，得到培训计划申请
            TrainPlan trainPlan = trainPlanService.selectTrainPlanById(trainPlanId);
            if (trainPlan != null && trainPlan.getTrainplanApplication() != null) examApplicationVotemp.setTrainplanApplication(trainPlan.getTrainplanApplication());
            // 根据班级id找到培训班级信息
            TrainClass trainClass = trainClassService.selectTrainClassById(classId);
            if (trainClass != null) BeanUtils.copyProperties(trainClass, examApplicationVotemp);

            examApplicationVotemp.setId(examApplicationId);

            examApplicationVos.add(examApplicationVotemp);
        }
        return examApplicationVos;
    }

    @Override
    public int jingbanrenSubmitExamApplication(ExamApplication examApplication) {
        examApplication.setAuditId(SecurityUtils.getUserId());
        if (examApplication.getIsPass() == 1) {
            examApplication.setApprovalProcessSign(2L);
            examApplication.setIsPass(0);
        } else {
            examApplication.setApprovalProcessSign(0L);
            examApplication.setIsPass(-1);
        }

        return examApplicationMapper.updateExamApplication(examApplication);

    }

    @Override
    public int fuzerenSubmitExamApplcation(ExamApplication examApplication) {
        examApplication.setApprovalId(SecurityUtils.getUserId());
        if (examApplication.getIsPass() == 1) {
            examApplication.setApprovalProcessSign(3L);
            examApplication.setIsPass(0);
        } else {
            examApplication.setApprovalProcessSign(0L);
            examApplication.setIsPass(-1);
        }

        return examApplicationMapper.updateExamApplication(examApplication);
    }

    @Override
    public List<ExamApplicationVo> selectkaoshijigouExamApplicationVoList(ExamApplicationVo examApplicationVo) {
        QueryWrapper<ExamApplication> examApplicationQueryWrapper = new QueryWrapper<>();
        examApplicationQueryWrapper.eq(examApplicationVo.getExamPlace() != null, "exam_place", examApplicationVo.getExamPlace());
        examApplicationQueryWrapper.eq("is_deleted", 0);
        examApplicationQueryWrapper.eq( "approval_process_sign", 3);
        List<ExamApplication> examApplications = examApplicationMapper.selectList(examApplicationQueryWrapper);
        // 存储答案返回对象
        List<ExamApplicationVo> examApplicationVos = new ArrayList<>();
        List<StudentInformationVo> studentInformationVoList = new ArrayList<>();
        // 将所有信息填入Vo中
        for (ExamApplication examApplication : examApplications) {
            ExamApplicationVo examApplicationVotemp = new ExamApplicationVo();
            // 将考试申请表的内容复制到其Vo类中
            BeanUtils.copyProperties(examApplication, examApplicationVotemp);
            // 得到考试申请表id
            Long examApplicationId = examApplication.getId();
            // 通过考试申请表id找到考试申请表中的学生
            QueryWrapper<ExamApplicationStudent> examApplicationStudentQueryWrapper = new QueryWrapper<>();
            examApplicationStudentQueryWrapper.eq("exam_application_id", examApplicationId);
            List<ExamApplicationStudent> examApplicationStudents = examApplicationStudentMapper.selectList(examApplicationStudentQueryWrapper);
            // 培训计划id
            Long trainPlanId = 0L;
            Long classId = 0L;
            // 循环考试申请表中的学生信息
            for (ExamApplicationStudent examApplicationStudent : examApplicationStudents) {
                // 通过学生id找到学生信息表
                Long studentId = examApplicationStudent.getStudentId();
                QueryWrapper<StudentInformation> studentInformationQueryWrapper = new QueryWrapper<>();
                studentInformationQueryWrapper.eq("id", studentId);
                List<StudentInformation> studentInformationList = studentInformationService.list(studentInformationQueryWrapper);

                // 遍历学生信息表
                for (StudentInformation studentInformation : studentInformationList) {
                    classId = studentInformation.getClassId();
                    // 通过学生编号查询学生记录表
                    String serialNumber = studentInformation.getSerialNumber();
                    QueryWrapper<StudentProcessRecord> studentProcessRecordQueryWrapper = new QueryWrapper<>();
                    studentProcessRecordQueryWrapper.eq("serial_number", serialNumber);
                    StudentProcessRecord studentProcessRecord = studentProcessRecordService.getOne(studentProcessRecordQueryWrapper);
                    // 得到培训计划id
                    trainPlanId = studentProcessRecord.getTrainPlanId();
                    // 将信息导入StudentInfoVo类中
                    StudentInformationVo studentInformationVo = new StudentInformationVo();
                    BeanUtils.copyProperties(studentInformation, studentInformationVo);
                    BeanUtils.copyProperties(studentProcessRecord, studentInformationVo);
                    // 将信息加入到返回集合中
                    studentInformationVoList.add(studentInformationVo);
                }
            }

            // 将学生集合加入考试申请表Vo中
            if (studentInformationVoList != null) examApplicationVotemp.setStudentInformationVoList(studentInformationVoList);
            // 通过培训计划id找到培训计划表，得到培训计划申请
            TrainPlan trainPlan = trainPlanService.selectTrainPlanById(trainPlanId);
            if (trainPlan != null && trainPlan.getTrainplanApplication() != null) examApplicationVotemp.setTrainplanApplication(trainPlan.getTrainplanApplication());
            // 根据班级id找到培训班级信息
            TrainClass trainClass = trainClassService.selectTrainClassById(classId);
            if (trainClass != null) BeanUtils.copyProperties(trainClass, examApplicationVotemp);

            examApplicationVotemp.setId(examApplicationId);

            examApplicationVos.add(examApplicationVotemp);
        }
        return examApplicationVos;
    }

    @Override
    public List<ExamApplicationVo> selectPaymentVoList(ExamApplicationVo examApplicationVo) {
        QueryWrapper<ExamApplication> examApplicationQueryWrapper = new QueryWrapper<>();
        examApplicationQueryWrapper.eq(examApplicationVo.getExamPlace() != null, "exam_place", examApplicationVo.getExamPlace());
        examApplicationQueryWrapper.eq("is_deleted", 0);
        examApplicationQueryWrapper.eq( "approval_process_sign", 4);
        List<ExamApplication> examApplications = examApplicationMapper.selectList(examApplicationQueryWrapper);
        // 存储答案返回对象
        List<ExamApplicationVo> examApplicationVos = new ArrayList<>();
        List<StudentInformationVo> studentInformationVoList = new ArrayList<>();
        // 将所有信息填入Vo中
        for (ExamApplication examApplication : examApplications) {
            ExamApplicationVo examApplicationVotemp = new ExamApplicationVo();
            // 将考试申请表的内容复制到其Vo类中
            BeanUtils.copyProperties(examApplication, examApplicationVotemp);

            // 得到考试申请表id
            Long examApplicationId = examApplication.getId();
            // 通过考试申请表id找到考试申请表中的学生
            QueryWrapper<ExamApplicationStudent> examApplicationStudentQueryWrapper = new QueryWrapper<>();
            examApplicationStudentQueryWrapper.eq("exam_application_id", examApplicationId);
            List<ExamApplicationStudent> examApplicationStudents = examApplicationStudentMapper.selectList(examApplicationStudentQueryWrapper);
            // 培训计划id
            Long trainPlanId = 0L;
            Long classId = 0L;
            // 循环考试申请表中的学生信息
            for (ExamApplicationStudent examApplicationStudent : examApplicationStudents) {
                // 通过学生id找到学生信息表
                Long studentId = examApplicationStudent.getStudentId();
                QueryWrapper<StudentInformation> studentInformationQueryWrapper = new QueryWrapper<>();
                studentInformationQueryWrapper.eq("id", studentId);
                List<StudentInformation> studentInformationList = studentInformationService.list(studentInformationQueryWrapper);

                // 遍历学生信息表
                for (StudentInformation studentInformation : studentInformationList) {
                    classId = studentInformation.getClassId();
                    // 通过学生编号查询学生记录表
                    String serialNumber = studentInformation.getSerialNumber();
                    QueryWrapper<StudentProcessRecord> studentProcessRecordQueryWrapper = new QueryWrapper<>();
                    studentProcessRecordQueryWrapper.eq("serial_number", serialNumber);
                    StudentProcessRecord studentProcessRecord = studentProcessRecordService.getOne(studentProcessRecordQueryWrapper);
                    // 得到培训计划id
                    trainPlanId = studentProcessRecord.getTrainPlanId();
                    // 将信息导入StudentInfoVo类中
                    StudentInformationVo studentInformationVo = new StudentInformationVo();
                    BeanUtils.copyProperties(studentInformation, studentInformationVo);
                    BeanUtils.copyProperties(studentProcessRecord, studentInformationVo);
                    // 将信息加入到返回集合中
                    studentInformationVoList.add(studentInformationVo);
                }
            }

            // 将学生集合加入考试申请表Vo中
            if (studentInformationVoList != null) examApplicationVotemp.setStudentInformationVoList(studentInformationVoList);
            // 通过培训计划id找到培训计划表，得到培训计划申请
            TrainPlan trainPlan = trainPlanService.selectTrainPlanById(trainPlanId);
            if (trainPlan != null && trainPlan.getTrainplanApplication() != null) examApplicationVotemp.setTrainplanApplication(trainPlan.getTrainplanApplication());
            // 根据班级id找到培训班级信息
            TrainClass trainClass = trainClassService.selectTrainClassById(classId);
            if (trainClass != null) BeanUtils.copyProperties(trainClass, examApplicationVotemp);

            examApplicationVotemp.setId(examApplicationId);

            examApplicationVos.add(examApplicationVotemp);
        }
        return examApplicationVos;
    }

    @Override
    public List<ExamApplicationVo> selectExamApplicationVoImportList(ExamApplicationVo examApplicationVo) {
        QueryWrapper<ExamApplication> examApplicationQueryWrapper = new QueryWrapper<>();
        examApplicationQueryWrapper.eq(examApplicationVo.getExamPlace() != null, "exam_place", examApplicationVo.getExamPlace());
        examApplicationQueryWrapper.eq("is_deleted", 0);
        examApplicationQueryWrapper.eq( "approval_process_sign", 5);
        List<ExamApplication> examApplications = examApplicationMapper.selectList(examApplicationQueryWrapper);
        // 存储答案返回对象
        List<ExamApplicationVo> examApplicationVos = new ArrayList<>();
        List<StudentInformationVo> studentInformationVoList = new ArrayList<>();
        // 将所有信息填入Vo中
        for (ExamApplication examApplication : examApplications) {
            ExamApplicationVo examApplicationVotemp = new ExamApplicationVo();
            // 将考试申请表的内容复制到其Vo类中
            BeanUtils.copyProperties(examApplication, examApplicationVotemp);

            // 得到考试申请表id
            Long examApplicationId = examApplication.getId();
            // 通过考试申请表id找到考试申请表中的学生
            QueryWrapper<ExamApplicationStudent> examApplicationStudentQueryWrapper = new QueryWrapper<>();
            examApplicationStudentQueryWrapper.eq("exam_application_id", examApplicationId);
            List<ExamApplicationStudent> examApplicationStudents = examApplicationStudentMapper.selectList(examApplicationStudentQueryWrapper);
            // 培训计划id
            Long trainPlanId = 0L;
            Long classId = 0L;
            // 循环考试申请表中的学生信息
            for (ExamApplicationStudent examApplicationStudent : examApplicationStudents) {
                // 通过学生id找到学生信息表
                Long studentId = examApplicationStudent.getStudentId();
                QueryWrapper<StudentInformation> studentInformationQueryWrapper = new QueryWrapper<>();
                studentInformationQueryWrapper.eq("id", studentId);
                List<StudentInformation> studentInformationList = studentInformationService.list(studentInformationQueryWrapper);

                // 遍历学生信息表
                for (StudentInformation studentInformation : studentInformationList) {
                    classId = studentInformation.getClassId();
                    // 通过学生编号查询学生记录表
                    String serialNumber = studentInformation.getSerialNumber();
                    QueryWrapper<StudentProcessRecord> studentProcessRecordQueryWrapper = new QueryWrapper<>();
                    studentProcessRecordQueryWrapper.eq("serial_number", serialNumber);
                    StudentProcessRecord studentProcessRecord = studentProcessRecordService.getOne(studentProcessRecordQueryWrapper);
                    // 得到培训计划id
                    trainPlanId = studentProcessRecord.getTrainPlanId();
                    // 将信息导入StudentInfoVo类中
                    StudentInformationVo studentInformationVo = new StudentInformationVo();
                    BeanUtils.copyProperties(studentInformation, studentInformationVo);
                    BeanUtils.copyProperties(studentProcessRecord, studentInformationVo);
                    // 将信息加入到返回集合中
                    studentInformationVoList.add(studentInformationVo);
                }
            }

            // 将学生集合加入考试申请表Vo中
            if (studentInformationVoList != null) examApplicationVotemp.setStudentInformationVoList(studentInformationVoList);
            // 通过培训计划id找到培训计划表，得到培训计划申请
            TrainPlan trainPlan = trainPlanService.selectTrainPlanById(trainPlanId);
            if (trainPlan != null && trainPlan.getTrainplanApplication() != null) examApplicationVotemp.setTrainplanApplication(trainPlan.getTrainplanApplication());
            // 根据班级id找到培训班级信息
            TrainClass trainClass = trainClassService.selectTrainClassById(classId);
            if (trainClass != null) BeanUtils.copyProperties(trainClass, examApplicationVotemp);

            examApplicationVotemp.setId(examApplicationId);

            examApplicationVos.add(examApplicationVotemp);
        }
        return examApplicationVos;
    }

    // 添加到考试合格申请
    @Override
    public int addToExamCertificateApplication(Long applicationId) {
    // 通过考试申请表id查询考试申请表
        ExamApplication examApplication = examApplicationMapper.selectById(applicationId);
        examApplication.setApprovalProcessSign(6L);
        examApplication.setIsPass(1);
        int i = examApplicationMapper.updateById(examApplication);
        // 通过考试申请id查询考试申请学员表
        QueryWrapper<ExamApplicationStudent> examApplicationStudentQueryWrapper = new QueryWrapper<>();
        examApplicationStudentQueryWrapper.eq("exam_application_id", applicationId);
        List<ExamApplicationStudent> examApplicationStudents = examApplicationStudentMapper.selectList(examApplicationStudentQueryWrapper);
        // 将考试申请表的信息加入到考试合格证明表中
        ExamPassCertificate examPassCertificate = new ExamPassCertificate();
        // 通过学生id找到培训班级表中的班级期次
        Long studentId = examApplicationStudents.get(0).getStudentId();
        StudentInformation studentInformation = studentInformationMapper.selectById(studentId);
        Long classId = studentInformation.getClassId();
        // 通过班级id找到班级信息
        TrainClass trainClass = trainClassService.selectTrainClassById(classId);
        // 得到班级期次将其放入考试合格证明表中
        String classesTerm = trainClass.getClassesTerm();
        examPassCertificate.setClassTerm(classesTerm);
        examPassCertificate.setExamTime(examApplication.getExamStartTime());
        examPassCertificate.setReviewTime(examApplication.getExamEndTime());
        examPassCertificate.setOperationExamTime(examApplication.getOperationExamStartTime());
        examPassCertificate.setOperationReviewTime(examApplication.getOperationReviewStartTime());
        examPassCertificate.setCreateId(examApplication.getCreateId());
        examPassCertificate.setCreateTime(DateUtils.getNowDate());


        // 将考试合格申请表添加到数据库中
        examPassCertificateService.save(examPassCertificate);

        // 将插入后返回的考试合格申请表id，添加到考试合格学员表中
        Long examPassCertificateId = examPassCertificate.getId();
        for (ExamApplicationStudent examApplicationStudent : examApplicationStudents) {
            ExamPassStudent examPassStudent = new ExamPassStudent();
            Long studentId1 = examApplicationStudent.getStudentId();
            examPassStudent.setStudentId(studentId1);
            examPassStudent.setExamPassId(examPassCertificateId);
            examPassStudentService.save(examPassStudent);
        }
        return i;
    }


    @Override
    public int uploadExamApplication(ExamApplication examApplication) {

        return examApplicationMapper.updateExamApplication(examApplication);
    }

    // 盖章1考试申请表
    @Override
    public int gaizhang1Application(Long applicationId) {
        ExamApplication examApplication = examApplicationMapper.selectById(applicationId);

        examApplication.setExamOperationSheet(SecurityUtils.getUserId());
        examApplicationMapper.updateExamApplication(examApplication);

        // 通过id得到考试申请表信息
        ExamApplicationVo examApplicationVo = getExamApplicationVoById(examApplication.getId());
        // 通过考试申请表信息生成pdf
        try {
            // 存储pdf地址
            String pdfUrl = getPdfTableByApplicationId(examApplicationVo);
            // 根据pdf真实地址生成其虚拟地址
            String pdfVirtualUrlByTrueUrl = getPdfVirtualUrlByTrueUrl(pdfUrl);

            examApplication.setExamApplicationPdf(pdfVirtualUrlByTrueUrl);
            examApplication.setUpdateTime(DateUtils.getNowDate());
            examApplication.setUpdateId(SecurityUtils.getUserId());
            examApplication.setApprovalProcessSign(5L);
            int i = examApplicationMapper.updateExamApplication(examApplication);

            int falg = 1;
            if (i == 1 && "".equals(pdfUrl)) falg = 0;
            return falg;
        } catch (RuntimeException e) {
             throw new RuntimeException(e);
        }

    }

    // 根据pdf真实地址生成其虚拟地址
    public String getPdfVirtualUrlByTrueUrl(String pdfUrl) {
        if (pdfUrl != null && !pdfUrl.equals(""))
        {
            int lastIndexOf = pdfUrl.lastIndexOf("九");
            pdfUrl = "/image/" + pdfUrl.substring(lastIndexOf);
        }

        return pdfUrl;
    }

    @Override
    public int updateExamPlacegetGrade(ExamApplication examApplication) {
        return examApplicationService.uploadExamApplication(examApplication);
    }


    // TODO 上传服务器时记得改地址
    // 通过考试申请表信息得到pdf
    private String getPdfTableByApplicationId(ExamApplicationVo examApplicationVo) {
        String qualifiedType1 = examApplicationVo.getQualifiedType();
        Integer template = -1;
        if (qualifiedType1.equals("105") || qualifiedType1.equals("106")) template = 1;
        else if (qualifiedType1.equals("107")) template = 4;
            // 添加第一行数据
        List<String> oneList = new ArrayList<>();
        // 添加申报单位名称
        if (examApplicationVo.getApplicationUnit() != null) oneList.add(examApplicationVo.getApplicationUnit());
        else oneList.add("");
        // 添加培训班期次
        if (examApplicationVo.getClassTerm() != null) oneList.add(examApplicationVo.getClassTerm());
        else oneList.add("");

        // 添加第二行数据
        List<String> twoList = new ArrayList<>();
        twoList.add("");
        twoList.add("");
        if (examApplicationVo.getSum() != null)twoList.add(examApplicationVo.getSum().toString());
        else twoList.add("");

        if (examApplicationVo.getSendTime() != null) twoList.add(DateUtils.getFormatTime(examApplicationVo.getSendTime().toString()));
        else twoList.add("");

        // 添加表格内容
        // 通过考试申请表id得到考试申请学生信息
        List<StudentInformationVo> studentInformationVo = getExamApplicationStudentInfoByExamApplicationId(examApplicationVo.getId());

        int cnt = 0;
        // 将学生信息存入pdf表格
        List<List<String>> content = new ArrayList<>();
        for (StudentInformationVo studentInformationVoTemp : studentInformationVo) {
            // 定义每行数据
            List<String> line = new ArrayList<>();
            if (studentInformationVoTemp.getIdCard() != null) line.add(studentInformationVoTemp.getIdCard());
            else line.add("");
            if (studentInformationVoTemp.getName() != null) line.add(studentInformationVoTemp.getName());
            else line.add("");
            if (studentInformationVoTemp.getName() != null) line.add(studentInformationVoTemp.getWorkplace());
            else line.add("");
            if (studentInformationVoTemp.getPhone() != null) line.add(studentInformationVoTemp.getPhone());
            else line.add("");
            String operationType = examApplicationVo.getOperationType();
            String qualifiedType = examApplicationVo.getQualifiedType();
            if (qualifiedType.equals("107")) {
                if (operationType != null) {
                    SysDictData dictData = dictDataService.selectDictDataById(Long.parseLong(operationType));
                    line.add(dictData.getDictLabel());
                } else line.add("");
            } else if (qualifiedType.equals("106") || qualifiedType.equals("105")) {
                SysDictData dictData = dictDataService.selectDictDataById(Long.parseLong(qualifiedType));
                String workKind = examApplicationVo.getWorkKind();
                if (workKind != null && !workKind.equals("")) {
                    SysDictData dictData1 = dictDataService.selectDictDataById(Long.parseLong(workKind));
                    line.add(dictData.getDictLabel() + dictData1.getDictLabel());
                } else line.add("");
            } else line.add("");

            Integer trainIsPass = studentInformationVoTemp.getTrainIsPass();
            if (trainIsPass == 1) line.add("合格");
            else if (trainIsPass == 0) line.add("不合格");
            else line.add("");
            if (studentInformationVoTemp.getApplyDataNumber() != null) line.add(studentInformationVoTemp.getApplyDataNumber().toString());
            else line.add("");
            if (studentInformationVoTemp.getIsAgent() == 1) line.add("是");
            else if (studentInformationVoTemp.getIsAgent() == 0) line.add("否");
            else line.add("");
            cnt ++ ;
            content.add(line);
        }

        // 填入最终数据列表
        List<String> finalDataList = new ArrayList<>();
        finalDataList.add(cnt + "");
        String examKind = examApplicationVo.getExamKind();
        if (examKind.equals("1")) finalDataList.add("初训");
        else if(examKind.equals("2")) finalDataList.add("复训");
        else if (examKind.equals("3")) finalDataList.add("换证");
        else finalDataList.add("");
        String examPlace = examApplicationVo.getExamPlace();
        String exam_place = "";
        if (examPlace.equals("1")) exam_place = "浔阳区考试点";
        else if(examPlace.equals("2")) exam_place = "濂溪区考试点";
        if (exam_place != "")  finalDataList.add(exam_place);
        else finalDataList.add("");

        // 填入考试时间和补考时间
        if (examApplicationVo.getQualifiedType().equals("105") || examApplicationVo.getQualifiedType().equals("106")) {
            // 主要负责人或安全管理人员
            String startTime = DateUtils.getFormatTime(examApplicationVo.getExamStartTime().toString()); // 考试开始时间
            String endTime = DateUtils.getFormatTime(examApplicationVo.getExamEndTime().toString()); // 考试结束时间
            String commonTime = startTime.substring(0, 10);
            String startSuffix = startTime.substring(11, startTime.length() - 3);
            String endSuffix = endTime.substring(11, endTime.length() - 3);
            String finallyTime = commonTime + " " + startSuffix + "-" + endSuffix;
            if (finallyTime != null) finalDataList.add(finallyTime);
            else finalDataList.add("");
            // 补考
            String reviewStartTime = DateUtils.getFormatTime(examApplicationVo.getReviewStartTime().toString()); // 考试开始时间
            String reviewEndTime = DateUtils.getFormatTime(examApplicationVo.getReviewEndTime().toString()); // 考试结束时间
            String reviewCommonTime = reviewStartTime.substring(0, 10);
            String reviewStartSuffix = reviewStartTime.substring(11, reviewStartTime.length() - 3);
            String reviewEndSuffix = reviewEndTime.substring(11, reviewEndTime.length() - 3);
            String reviewFinallyTime = reviewCommonTime + " " + reviewStartSuffix + "-" + reviewEndSuffix;

            if (reviewFinallyTime != null) finalDataList.add(reviewFinallyTime);
            else finalDataList.add("");
        } else if (examApplicationVo.getQualifiedType().equals("107")) {
            // 特作
            String startTime = DateUtils.getFormatTime(examApplicationVo.getOperationExamStartTime().toString()); // 补考开始时间
            String endTime = DateUtils.getFormatTime(examApplicationVo.getOperationExamEndTime().toString()); // 补考结束时间
            String commonTime = startTime.substring(0, 10);
            String startSuffix = startTime.substring(11, startTime.length() - 3);
            String endSuffix = endTime.substring(11, endTime.length() - 3);
            String finallyTime = commonTime + " " + startSuffix + "-" + endSuffix;
            if (finallyTime != null) finalDataList.add(finallyTime);
            else finalDataList.add("");

            // 补考
            String reviewStartTime = DateUtils.getFormatTime(examApplicationVo.getOperationReviewStartTime().toString()); // 考试开始时间
            String reviewEndTime = DateUtils.getFormatTime(examApplicationVo.getOperationReviewEndTime().toString()); // 考试结束时间
            String reviewCommonTime = reviewStartTime.substring(0, 10);
            String reviewStartSuffix = reviewStartTime.substring(11, reviewStartTime.length() - 3);
            String reviewEndSuffix = reviewEndTime.substring(11, reviewEndTime.length() - 3);
            String reviewFinallyTime = reviewCommonTime + " " + reviewStartSuffix + "-" + reviewEndSuffix;

            if (reviewFinallyTime != null) finalDataList.add(reviewFinallyTime);
            else finalDataList.add("");
        } else {
            finalDataList.add("");
            finalDataList.add("");
        }

        // 审批信息列表
        List<String> approvalList = new ArrayList<>();
        approvalList.add("");
        approvalList.add("");

        approvalList.add("九江市安全生产考试机构");


        // 盖章图片
        Map<String, Image> chapterPicture = new HashMap<>();

        try {
            String applicationUnitSheet1 = examApplicationVo.getApplicationUnitSheet();
            if (applicationUnitSheet1 != null && !applicationUnitSheet1.equals("")) {
                String applicationUnitSheet = "D:/ruoyi/uploadPath" + applicationUnitSheet1.substring(8);
//                String applicationUnitSheet = "C:/wusihao/uploadPath" + applicationUnitSheet1.substring(8);
//            Image image1 = new Image(ImageDataFactory.create(this.getClass().getClassLoader().getResource(applicationUnitSheet)));
                Image image1 = new Image(ImageDataFactory.create(applicationUnitSheet));
                chapterPicture.put("申报单位", image1);
            }

            String examUnitSheet = examApplicationVo.getExamUnitSheet();
            if (examUnitSheet != null && !examUnitSheet.equals("")) {
                String examApplicationChapter ="D:/ruoyi/uploadPath" +  examUnitSheet.substring(8);
//                String examApplicationChapter ="C:/wusihao/uploadPath" +  examUnitSheet.substring(8);
                Image image2 = new Image(ImageDataFactory.create(examApplicationChapter));
                chapterPicture.put("考试机构：", image2);
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        // 签字图片
        Map<String, Image> signMap = new HashMap<>();

        try {
            String shenheren = examApplicationVo.getShenheren();
            if (shenheren != null && !shenheren.equals("")) {
                shenheren = "D:/ruoyi/uploadPath" + shenheren.substring(8);
//                shenheren = "C:/wusihao/uploadPath" + shenheren.substring(8);
                Image shenherenimage = new Image(ImageDataFactory.create(shenheren));
                signMap.put("审核人", shenherenimage);
            }

            String unitManager = examApplicationVo.getUnitManager();
            if (unitManager != null && !unitManager.equals("")) {
                unitManager = "D:/ruoyi/uploadPath" + unitManager.substring(8);
//                unitManager = "C:/wusihao/uploadPath" + unitManager.substring(8);
                Image unitManagerimage = new Image(ImageDataFactory.create(unitManager));
                signMap.put("单位经办人", unitManagerimage);
            }
            String shenpiren = examApplicationVo.getShenpiren();
            if (shenpiren != null && !shenpiren.equals("")) {
                shenpiren = "D:/ruoyi/uploadPath" + shenpiren.substring(8);
//                shenpiren = "C:/wusihao/uploadPath" + shenpiren.substring(8);
                Image shenpirenimage = new Image(ImageDataFactory.create(shenpiren));
                signMap.put("审批人", shenpirenimage);
            }
            String unitHeader = examApplicationVo.getUnitHeader();
            if (unitHeader != null && !unitHeader.equals("")) {
                unitHeader = "D:/ruoyi/uploadPath" + unitHeader.substring(8);
//                unitHeader = "C:/wusihao/uploadPath" + unitHeader.substring(8);
                Image unitHeaderimage = new Image(ImageDataFactory.create(unitHeader));
                signMap.put("单位负责人", unitHeaderimage);
            }
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
        // 生成pdf
        PdfReqVo pdfReqVo = new PdfReqVo();
        pdfReqVo.setTemplate(template);
        pdfReqVo.setOneBasicList(oneList);
        pdfReqVo.setTwoBasicList(twoList);
        pdfReqVo.setContent(content);
        pdfReqVo.setFinalDataList(finalDataList);
        pdfReqVo.setApprovalList(approvalList);
        pdfReqVo.setSealMap(chapterPicture);
        pdfReqVo.setSignMap(signMap);
        String pdfUrl = "";
        try {
            pdfUrl = PdfCreate.createPdf(pdfReqVo);
            return pdfUrl;
        } catch (Exception e) {
            return "";
        }
    }


    // 通过id生成考试申请表
    public ExamApplicationVo getExamApplicationVoById(Long id) {

        ExamApplication examApplication = examApplicationService.getById(id);
        ExamApplicationVo examApplicationVo = new ExamApplicationVo();

        BeanUtils.copyProperties(examApplication, examApplicationVo);
        // 通过考试申请id查询考试申请学生id
        Long applicationId = examApplication.getId();
        QueryWrapper<ExamApplicationStudent> examApplicationStudentQueryWrapper = new QueryWrapper<>();
        examApplicationStudentQueryWrapper.eq("exam_application_id", applicationId);
        List<ExamApplicationStudent> examApplicationStudents = examApplicationStudentMapper.selectList(examApplicationStudentQueryWrapper);
        Long studentId = examApplicationStudents.get(0).getStudentId();
        // 通过学生id查询学生信息表
        StudentInformation studentInformationServiceById = studentInformationService.getById(studentId);
        // 通过学生编号的到学生记录表，进而获取资格类型
        QueryWrapper<StudentProcessRecord> studentProcessRecordQueryWrapper = new QueryWrapper<>();
        studentProcessRecordQueryWrapper.eq("serial_number", studentInformationServiceById.getSerialNumber());
        StudentProcessRecord studentProcessRecordServiceOne = studentProcessRecordService.getOne(studentProcessRecordQueryWrapper);
        // 得到培训计划id
        Long trainPlanId = studentProcessRecordServiceOne.getTrainPlanId();
        // 查找培训计划信息
        TrainPlan trainPlanServiceById = trainPlanService.getById(trainPlanId);
        examApplicationVo.setWorkKind(trainPlanServiceById.getWorkKind());
        examApplicationVo.setOperationType(trainPlanServiceById.getOperationType());
        examApplicationVo.setQualifiedType(trainPlanServiceById.getQualifiedType());
        // 通过申报单位id得到申报单位信息, 单位经办人图片，单位负责人签字
        String applyUnitId = trainPlanServiceById.getApplyUnitId();
        QueryWrapper<TrainingInstitutionInfomation> trainingInstitutionInfomationQueryWrapper = new QueryWrapper<>();
        trainingInstitutionInfomationQueryWrapper.eq("create_id", Long.parseLong(applyUnitId));
        TrainingInstitutionInfomation trainingInstitutionInfomationServiceOne = trainingInstitutionInfomationService.getOne(trainingInstitutionInfomationQueryWrapper);
        String name = trainingInstitutionInfomationServiceOne.getName();
        if (name.equals("1")) examApplicationVo.setApplicationUnit("首佳");
        else if (name.equals("2")) examApplicationVo.setApplicationUnit("安信");
        else if (name.equals("3")) examApplicationVo.setApplicationUnit("瑞天");
        examApplicationVo.setApplicationUnitSheet(trainingInstitutionInfomationServiceOne.getApplicationUnitSheet());
        examApplicationVo.setUnitManager(trainingInstitutionInfomationServiceOne.getUnitManager());
        examApplicationVo.setUnitHeader(trainingInstitutionInfomationServiceOne.getUnitHeader());

        // 通过考试申请表id得到审核人审批人信息
        Long auditId = examApplication.getAuditId(); // 审核人id
        Long approvalId = examApplication.getApprovalId(); // 审批人id
        QueryWrapper<TrainingInstitutionInfomation> trainingInstitutionInfomationQueryWrapper3 = new QueryWrapper<>();
        trainingInstitutionInfomationQueryWrapper3.eq("create_id", auditId);
        TrainingInstitutionInfomation trainingInstitutionInfomationServiceOne3 = trainingInstitutionInfomationService.getOne(trainingInstitutionInfomationQueryWrapper3);
        examApplicationVo.setShenheren(trainingInstitutionInfomationServiceOne3.getApplicationUnitSheet());
        QueryWrapper<TrainingInstitutionInfomation> trainingInstitutionInfomationQueryWrapper4 = new QueryWrapper<>();
        trainingInstitutionInfomationQueryWrapper4.eq("create_id", approvalId);
        TrainingInstitutionInfomation trainingInstitutionInfomationServiceOne4 = trainingInstitutionInfomationService.getOne(trainingInstitutionInfomationQueryWrapper4);
        examApplicationVo.setShenpiren(trainingInstitutionInfomationServiceOne4.getApplicationUnitSheet());

        // 通过考试机构盖章id得到考试机构盖章
        Long examOperationSheet = examApplication.getExamOperationSheet();
        QueryWrapper<TrainingInstitutionInfomation> trainingInstitutionInfomationQueryWrapper5 = new QueryWrapper<>();
        trainingInstitutionInfomationQueryWrapper5.eq("create_id", examOperationSheet);
        TrainingInstitutionInfomation trainingInstitutionInfomationServiceOne5 = trainingInstitutionInfomationService.getOne(trainingInstitutionInfomationQueryWrapper5);
        examApplicationVo.setExamUnitSheet(trainingInstitutionInfomationServiceOne5.getApplicationUnitSheet());
        return examApplicationVo;
    }


    // 通过id得到考试申请表信息
    @Override
    public ExamApplicationVo selectExamApplicationVoById(Long id) {

        ExamApplication examApplication = examApplicationService.getById(id);
        ExamApplicationVo examApplicationVo = new ExamApplicationVo();

        BeanUtils.copyProperties(examApplication, examApplicationVo);
        // 通过考试申请id查询考试申请学生id
        Long applicationId = examApplication.getId();
        QueryWrapper<ExamApplicationStudent> examApplicationStudentQueryWrapper = new QueryWrapper<>();
        examApplicationStudentQueryWrapper.eq("exam_application_id", applicationId);
        List<ExamApplicationStudent> examApplicationStudents = examApplicationStudentMapper.selectList(examApplicationStudentQueryWrapper);
        Long studentId = examApplicationStudents.get(0).getStudentId();
        // 通过学生id查询学生信息表
        StudentInformation studentInformationServiceById = studentInformationService.getById(studentId);
        // 通过学生编号的到学生记录表，进而获取资格类型
        QueryWrapper<StudentProcessRecord> studentProcessRecordQueryWrapper = new QueryWrapper<>();
        studentProcessRecordQueryWrapper.eq("serial_number", studentInformationServiceById.getSerialNumber());
        StudentProcessRecord studentProcessRecordServiceOne = studentProcessRecordService.getOne(studentProcessRecordQueryWrapper);
        // 得到培训计划id
        Long trainPlanId = studentProcessRecordServiceOne.getTrainPlanId();
        // 得到资格类型
        TrainPlan trainPlanServiceById = trainPlanService.getById(trainPlanId);
        String qualifiedType = trainPlanServiceById.getQualifiedType();
        examApplicationVo.setExamPlace(trainPlanServiceById.getExamPlace());
        examApplicationVo.setTrainplanApplication(trainPlanServiceById.getTrainplanApplication());
        examApplicationVo.setQualifiedType(qualifiedType);
        return examApplicationVo;
    }
}
